
  <title>商品管理</title>
  <div class="layui-card">
    <div class="layui-card-body">
      <div class="layui-tab layui-tab-brief" lay-filter="goods-list-tabs">
        <ul class="layui-tab-title" style="margin-bottom: 10px;">
        	<li class="layui-this">全部书评</li>
          <li>待审核书评</li>
          <li>审核通过书评</li>
          <li>审核未通过书评</li>
        </ul>
        <div class="layui-tab-content">
          <div class="layui-tab-item layui-show" id="status1">
            <table id="LAY-good-list-status1" lay-filter="LAY-good-list-status1"></table>
          </div>
          <div class="layui-tab-item" id="status2">
              <table id="LAY-good-list-status2" lay-filter="LAY-good-list-status2"></table>
          </div>
          <div class="layui-tab-item" id="status3">
              <table id="LAY-good-list-status3" lay-filter="LAY-good-list-status3"></table>
          </div>
          <div class="layui-tab-item" id="status4">
            <table id="LAY-good-list-status4" lay-filter="LAY-good-list-status4"></table>
          </div>
          <script type="text/html" id="LAY-good-list-table-edit">
            <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
          </script>
          <script type="text/html" id="user_avatar">
            <img src="{{d.user_avatar}}" alt="" style="width:80px; height: 80px;">
          </script>
          <script type="text/html" id="LAY-good-list-table-img">
            <img src="{{d.book_image}}" alt="" style="width:82px; height: 110px;">
          </script>
          <script type="text/html" id="user_name">
						<a lay-event="detail" style="cursor: pointer;color:blue">{{d.user_nickname}}</a>
					</script>
          <script type="text/html" id="LAY-good-list-recycle">
            <p>{{parseInt(d.state) == 0? '待审核':parseInt(d.state) ==1?'审核通过':'审核未通过'}}</p>
          </script>
        </div>
      </div>
    </div>
  </div>
<script>
layui.use(['admin', 'table', 'form', 'upload'], function(){
    var table = layui.table
    ,form = layui.form
    ,admin = layui.admin
    ,upload = layui.upload
    ,view = layui.view
    ,element = layui.element
    ,$ = layui.$
    ,curr_tab = 0 //当前tab索引
	,cols = [
		[
			{
				align: 'center',
				width: 120,
				templet: '#user_avatar',
				title: '头像',
				field: 'user_avatar'
			}, {
				align: 'center',
				field: 'user_nickname',
				title: '用户',
				templet: '#user_name'
			},{
				align: 'center',
				width: 110,
				templet: '#LAY-good-list-table-img',
				title: '商品图片',
				field: 'book_image'
			}, {
				align: 'center',
				field: 'book_title',
				title: '评论的书',
			}, {
				align: 'center',
				field: 'book_author',
				title: '作者',
			}, {
				align: 'center',
				field: 'created_at_str',
				title: '提交时间'
			}, {
				align: 'center',
				field: 'state',
				templet: '#LAY-good-list-recycle',
				title: '审核状态'
			}, {
				align: 'center',
				fixed: 'right',
				title: '操作',
				toolbar: '#LAY-good-list-table-edit'
			}
		]
	];
	table.set({
		headers: { //通过 request 头传递
			'access-token': layui.data('layuiAdmin').access_token
		}
	});
	table.render({
		elem: '#LAY-good-list-status4',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book_comments?type=3',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"data": res.data.items, //解析数据列表
				"count": res.data._meta.total_count //解析数据长度
			}
		},
		cols: cols,
		page: true
	});
	table.render({
		elem: '#LAY-good-list-status3',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book_comments?type=2',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	table.render({
		elem: '#LAY-good-list-status2',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book_comments?type=1',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});

	table.render({
		elem: '#LAY-good-list-status1',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book_comments?type=0',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	// 监听tab切换
	element.on('tab(goods-list-tabs)', function(data) {
		curr_tab = data.index
	});

    //监听工具条
    table.on('tool(LAY-good-list-status1)', function(obj){
      var data = obj.data;
      if(obj.event === 'edit'){
        admin.popup({
        title: '编辑书评'
        ,area: ['80%', '80%']
        ,id: 'LAY-popup-content-tags'
        ,success: function(layero, index){
          view(this.id).render('book-review/all/add', data).done(function(){
            form.render(null, 'layuiadmin-form-tags');
		   	     $.ajax({
					    type: "GET",
					    dataType: "json",
					    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/show",
					    data: {
					    	id:data.id
					    },
					    headers: { //通过 request 头传递
			              'access-token': layui.data('layuiAdmin').access_token
			            },
								success: function(data){
								    $('#content1').text(data.data.content)
								},
								error: function(msg){
								  console.log(msg)
								}
						});
            if (parseInt(data.state) == 0) {
            	$('#btn-pass').show();
            }
            if (parseInt(data.state) == 1) {
            	$('#pass').show();
            	$('#status-1').show();
            }
            if (parseInt(data.state) == 2) {
            	$('#nopass').show();
            	$('#status-1').show();
            }
            //监听通过提交
            form.on('submit(layuiadmin-app-tags-submit)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	     $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':1
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
            //监听不通过提交
            form.on('submit(layuiadmin-app-tags-submit1)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':2
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
          });
        }
      });
      } else if (obj.event === 'detail') {
				admin.popup({
					title: '查看用户',
					area: ['80%', '96%'],
					id: 'LAY-popup-content-tags',
					success: function(layero, index) {
						view(this.id).render('user-manage/all/add', data).done(function() {
							var is_black = '';
							var titles = '';
							var contents = '';
							// 跳转收书列表
							$('#order_books1').click(function() {
								location.hash = '/buy-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转卖书列表
							$('#order_books').click(function() {
								location.hash = '/sale-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转订单退回列表
							$('#order_books2').click(function() {
								location.hash = '/return-order/order/index/user_id=' + data.user_id
								return false;
							})
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/user/show?id=" + data.user_id,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(parseInt(data.code) == 0) {
										$('#wechat_avatar1').attr('src', data.data.wechat_avatar)
										$('#wechat_nickname').text(data.data.wechat_nickname)
										$('#account').text(data.data.account)
										$('#created_at').text(data.data.created_at)
										$('#recommend_users_success').text(data.data.recommend_users_success)
										$('#buy_orders_num').text(data.data.buy_orders_num)
										$('#buy_books_num').text(data.data.buy_books_num)
										$('#sell_orders_num').text(data.data.sell_orders_num)
										$('#sell_books_num1').text(data.data.sell_books_num1)
										$('#sell_books_num2').text(data.data.sell_books_num2)
										$('#back_orders_num').text(data.data.back_orders_num)
										$('#back_books_num').text(data.data.back_books_num)
										$('#get_money').text(data.data.get_money)

										if(parseInt(data.data.is_official_account) == 1) {
											$('#wechat_nickname1').text('已关注公众号')
										} else {
											$('#wechat_nickname1').text('未关注公众号')
										}
										if(parseInt(data.data.is_black) == 1) {
											is_black = 0;
											$('#blacklist').text('取消标记黑名单');
											$('#blacklistUser').show();
											titles = '确认将用户取消标记';
											contents = '确认后，该用户的卖书权限将恢复，是否确认操作';
										} else {
											is_black = 1;
											$('#blacklist').text('标记为黑名单用户');
											titles = '确认将用户标记为黑名单';
											contents = '提交后，该用户卖书下单时将会被系统自动拒绝是否确认操作？';
										}
										$('#recommend_users_total').text(data.data.recommend_users_total)
										if(data.data.addresses.length > 0) {
											$('#base-address').show();
										}
										var _html = '';
										var _html1 = '';
										var _html2 = '';
										var num = 0;
										for(var i = 0; i < data.data.addresses.length; i++) {
											num += 1
											_html += '<li><p>地址信息' + num + '</p><p><span style="margin-right:20px">' + data.data.addresses[i].receiver + '</span>' + data.data.addresses[i].mobile + '</p><p>' + data.data.addresses[i].province_name + '' + data.data.addresses[i].city_name + '' + data.data.addresses[i].area_name + '' + data.data.addresses[i].address + '</p></li>';
										}
										$('#address-list').append(_html)
										for(var i = 0; i < data.data.account_records1.length; i++) {
											_html1 += '<tr><td>卖书（' + data.data.account_records1[i].books_num + '本）</td><td>' + data.data.account_records1[i].created_at + '</td><td>' + data.data.account_records1[i].platform_success_time + '</td><td>' + data.data.account_records1[i].actual_price + '</td></tr>';
										}
										$('#table1').append(_html1)
										for(var i = 0; i < data.data.account_records2.length; i++) {
											if(parseInt(data.data.account_records2[i].state) == 1) {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td>提现成功</td></tr>';
											} else {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td stle="color:red">提现失败</td></tr>';

											}
										}
										$('#table2').append(_html2)

										form.render();
									} else {
										layer.msg(data.message);
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
              // 黑名单加入与取消
							$('#blacklist').click(function() {
									//执行 Ajax 后重载
									layer.open({
							        type: 1
							        ,title: titles
							        ,area: '300px;'
							        ,shade: 0.8
							        ,id: 'LAY_layuipro'
							        ,btn: ['确认','取消',]
							        ,btnAlign: 'c'
							        ,moveType: 1 //拖拽模式，0或者1
							        ,content: '<div style="padding: 50px; line-height: 22px; background-color: #fff; color: #000; font-weight: 300;"><p>'+contents+'</p></div>'
							        ,success: function(layero){
							          var btn = layero.find('.layui-layer-btn');
							          btn.find('.layui-layer-btn0').click(function(){
													$.ajax({
															type: "POST",
															dataType: "json",
															url: "https://bookshop.dingdangtoy.com/api/admin/user/black",
															data: {
																'user_id':data.user_id,
																'is_black':is_black,
															},
															headers: {
																		'access-token': layui.data('layuiAdmin').access_token
																	},
														success: function(data){
															if(data.code == 0){
																layer.msg('操作成功');
																layui.table.reload('LAY-good-list-status1');
														    layui.table.reload('LAY-good-list-status2');
														    layui.table.reload('LAY-good-list-status3');
														    layui.table.reload('LAY-good-list-status4');
																setTimeout(function(){
																		window.parent.layer.closeAll();
																},1000)
															} else {
																layer.msg(data.message);
															}

														},
														error: function(msg){
															console.log(msg)
														}
													});
							          })
							        }
							      });
								return false;


							})
						});
					}
				});
			}
    });
    table.on('tool(LAY-good-list-status2)', function(obj){
      var data = obj.data;
      if(obj.event === 'edit'){
        admin.popup({
        title: '编辑书评'
        ,area: ['80%', '80%']
        ,id: 'LAY-popup-content-tags'
        ,success: function(layero, index){
          view(this.id).render('book-review/all/add', data).done(function(){
            form.render(null, 'layuiadmin-form-tags');
           $.ajax({
					    type: "GET",
					    dataType: "json",
					    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/show",
					    data: {
					    	id:data.id
					    },
					    headers: { //通过 request 头传递
			              'access-token': layui.data('layuiAdmin').access_token
			            },
								success: function(data){
								    $('#content1').text(data.data.content)
								},
								error: function(msg){
								  console.log(msg)
								}
						});
            if (parseInt(data.state) == 0) {
            	$('#btn-pass').show();
            }
            if (parseInt(data.state) == 1) {
            	$('#pass').show();
            	$('#status-1').show();
            }
            if (parseInt(data.state) == 2) {
            	$('#nopass').show();
            	$('#status-1').show();
            }
            //监听通过提交
            form.on('submit(layuiadmin-app-tags-submit)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':1
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
            //监听不通过提交
            form.on('submit(layuiadmin-app-tags-submit1)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':2
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
          });
        }
      });
      } else if (obj.event === 'detail') {
				admin.popup({
					title: '查看用户',
					area: ['80%', '96%'],
					id: 'LAY-popup-content-tags',
					success: function(layero, index) {
						view(this.id).render('user-manage/all/add', data).done(function() {
							var is_black = '';
							var titles = '';
							var contents = '';
							// 跳转收书列表
							$('#order_books1').click(function() {
								location.hash = '/buy-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转卖书列表
							$('#order_books').click(function() {
								location.hash = '/sale-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转订单退回列表
							$('#order_books2').click(function() {
								location.hash = '/return-order/order/index/user_id=' + data.user_id
								return false;
							})
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/user/show?id=" + data.user_id,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(parseInt(data.code) == 0) {
										$('#wechat_avatar1').attr('src', data.data.wechat_avatar)
										$('#wechat_nickname').text(data.data.wechat_nickname)
										$('#account').text(data.data.account)
										$('#created_at').text(data.data.created_at)
										$('#recommend_users_success').text(data.data.recommend_users_success)
										$('#buy_orders_num').text(data.data.buy_orders_num)
										$('#buy_books_num').text(data.data.buy_books_num)
										$('#sell_orders_num').text(data.data.sell_orders_num)
										$('#sell_books_num1').text(data.data.sell_books_num1)
										$('#sell_books_num2').text(data.data.sell_books_num2)
										$('#back_orders_num').text(data.data.back_orders_num)
										$('#back_books_num').text(data.data.back_books_num)
										$('#get_money').text(data.data.get_money)

										if(parseInt(data.data.is_official_account) == 1) {
											$('#wechat_nickname1').text('已关注公众号')
										} else {
											$('#wechat_nickname1').text('未关注公众号')
										}
										if(parseInt(data.data.is_black) == 1) {
											is_black = 0;
											$('#blacklist').text('取消标记黑名单');
											$('#blacklistUser').show();
											titles = '确认将用户取消标记';
											contents = '确认后，该用户的卖书权限将恢复，是否确认操作';
										} else {
											is_black = 1;
											$('#blacklist').text('标记为黑名单用户');
											titles = '确认将用户标记为黑名单';
											contents = '提交后，该用户卖书下单时将会被系统自动拒绝是否确认操作？';
										}
										$('#recommend_users_total').text(data.data.recommend_users_total)
										if(data.data.addresses.length > 0) {
											$('#base-address').show();
										}
										var _html = '';
										var _html1 = '';
										var _html2 = '';
										var num = 0;
										for(var i = 0; i < data.data.addresses.length; i++) {
											num += 1
											_html += '<li><p>地址信息' + num + '</p><p><span style="margin-right:20px">' + data.data.addresses[i].receiver + '</span>' + data.data.addresses[i].mobile + '</p><p>' + data.data.addresses[i].province_name + '' + data.data.addresses[i].city_name + '' + data.data.addresses[i].area_name + '' + data.data.addresses[i].address + '</p></li>';
										}
										$('#address-list').append(_html)
										for(var i = 0; i < data.data.account_records1.length; i++) {
											_html1 += '<tr><td>卖书（' + data.data.account_records1[i].books_num + '本）</td><td>' + data.data.account_records1[i].created_at + '</td><td>' + data.data.account_records1[i].platform_success_time + '</td><td>' + data.data.account_records1[i].actual_price + '</td></tr>';
										}
										$('#table1').append(_html1)
										for(var i = 0; i < data.data.account_records2.length; i++) {
											if(parseInt(data.data.account_records2[i].state) == 1) {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td>提现成功</td></tr>';
											} else {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td stle="color:red">提现失败</td></tr>';

											}
										}
										$('#table2').append(_html2)

										form.render();
									} else {
										layer.msg(data.message);
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
              // 黑名单加入与取消
							$('#blacklist').click(function() {
									//执行 Ajax 后重载
									layer.open({
							        type: 1
							        ,title: titles
							        ,area: '300px;'
							        ,shade: 0.8
							        ,id: 'LAY_layuipro'
							        ,btn: ['确认标记','取消',]
							        ,btnAlign: 'c'
							        ,moveType: 1 //拖拽模式，0或者1
							        ,content: '<div style="padding: 50px; line-height: 22px; background-color: #fff; color: #000; font-weight: 300;"><p>'+contents+'</p></div>'
							        ,success: function(layero){
							          var btn = layero.find('.layui-layer-btn');
							          btn.find('.layui-layer-btn0').click(function(){
													$.ajax({
															type: "POST",
															dataType: "json",
															url: "https://bookshop.dingdangtoy.com/api/admin/user/black",
															data: {
																'user_id':data.id,
																'is_black':is_black,
															},
															headers: {
																		'access-token': layui.data('layuiAdmin').access_token
																	},
														success: function(data){
															if(data.code == 0){
																layer.msg('操作成功');
																layui.table.reload('LAY-good-list-status1');
														    layui.table.reload('LAY-good-list-status2');
														    layui.table.reload('LAY-good-list-status3');
														    layui.table.reload('LAY-good-list-status4');
																setTimeout(function(){
																		window.parent.layer.closeAll();
																},1000)
															} else {
																layer.msg(data.message);
															}

														},
														error: function(msg){
															console.log(msg)
														}
													});
							          })
							        }
							      });
								return false;


							})
						});
					}
				});
			}
    });
    table.on('tool(LAY-good-list-status3)', function(obj){
      var data = obj.data;
      if(obj.event === 'edit'){
        admin.popup({
        title: '编辑书评'
        ,area: ['80%', '80%']
        ,id: 'LAY-popup-content-tags'
        ,success: function(layero, index){
          view(this.id).render('book-review/all/add', data).done(function(){
            form.render(null, 'layuiadmin-form-tags');
           $.ajax({
					    type: "GET",
					    dataType: "json",
					    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/show",
					    data: {
					    	id:data.id
					    },
					    headers: { //通过 request 头传递
			              'access-token': layui.data('layuiAdmin').access_token
			            },
								success: function(data){
								    $('#content1').text(data.data.content)
								},
								error: function(msg){
								  console.log(msg)
								}
						});
            if (parseInt(data.state) == 0) {
            	$('#btn-pass').show();
            }
            if (parseInt(data.state) == 1) {
            	$('#pass').show();
            	$('#status-1').show();
            }
            if (parseInt(data.state) == 2) {
            	$('#nopass').show();
            	$('#status-1').show();
            }
            //监听通过提交
            form.on('submit(layuiadmin-app-tags-submit)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':1
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
            //监听不通过提交
            form.on('submit(layuiadmin-app-tags-submit1)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':2
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
          });
        }
      });
      } else if (obj.event === 'detail') {
				admin.popup({
					title: '查看用户',
					area: ['80%', '96%'],
					id: 'LAY-popup-content-tags',
					success: function(layero, index) {
						view(this.id).render('user-manage/all/add', data).done(function() {
							var is_black = '';
							var titles = '';
							var contents = '';
							// 跳转收书列表
							$('#order_books1').click(function() {
								location.hash = '/buy-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转卖书列表
							$('#order_books').click(function() {
								location.hash = '/sale-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转订单退回列表
							$('#order_books2').click(function() {
								location.hash = '/return-order/order/index/user_id=' + data.user_id
								return false;
							})
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/user/show?id=" + data.user_id,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(parseInt(data.code) == 0) {
										$('#wechat_avatar1').attr('src', data.data.wechat_avatar)
										$('#wechat_nickname').text(data.data.wechat_nickname)
										$('#account').text(data.data.account)
										$('#created_at').text(data.data.created_at)
										$('#recommend_users_success').text(data.data.recommend_users_success)
										$('#buy_orders_num').text(data.data.buy_orders_num)
										$('#buy_books_num').text(data.data.buy_books_num)
										$('#sell_orders_num').text(data.data.sell_orders_num)
										$('#sell_books_num1').text(data.data.sell_books_num1)
										$('#sell_books_num2').text(data.data.sell_books_num2)
										$('#back_orders_num').text(data.data.back_orders_num)
										$('#back_books_num').text(data.data.back_books_num)
										$('#get_money').text(data.data.get_money)

										if(parseInt(data.data.is_official_account) == 1) {
											$('#wechat_nickname1').text('已关注公众号')
										} else {
											$('#wechat_nickname1').text('未关注公众号')
										}
										if(parseInt(data.data.is_black) == 1) {
											is_black = 0;
											$('#blacklist').text('取消标记黑名单');
											$('#blacklistUser').show();
											titles = '确认将用户取消标记';
											contents = '确认后，该用户的卖书权限将恢复，是否确认操作';
										} else {
											is_black = 1;
											$('#blacklist').text('标记为黑名单用户');
											titles = '确认将用户标记为黑名单';
											contents = '提交后，该用户卖书下单时将会被系统自动拒绝是否确认操作？';
										}
										$('#recommend_users_total').text(data.data.recommend_users_total)
										if(data.data.addresses.length > 0) {
											$('#base-address').show();
										}
										var _html = '';
										var _html1 = '';
										var _html2 = '';
										var num = 0;
										for(var i = 0; i < data.data.addresses.length; i++) {
											num += 1
											_html += '<li><p>地址信息' + num + '</p><p><span style="margin-right:20px">' + data.data.addresses[i].receiver + '</span>' + data.data.addresses[i].mobile + '</p><p>' + data.data.addresses[i].province_name + '' + data.data.addresses[i].city_name + '' + data.data.addresses[i].area_name + '' + data.data.addresses[i].address + '</p></li>';
										}
										$('#address-list').append(_html)
										for(var i = 0; i < data.data.account_records1.length; i++) {
											_html1 += '<tr><td>卖书（' + data.data.account_records1[i].books_num + '本）</td><td>' + data.data.account_records1[i].created_at + '</td><td>' + data.data.account_records1[i].platform_success_time + '</td><td>' + data.data.account_records1[i].actual_price + '</td></tr>';
										}
										$('#table1').append(_html1)
										for(var i = 0; i < data.data.account_records2.length; i++) {
											if(parseInt(data.data.account_records2[i].state) == 1) {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td>提现成功</td></tr>';
											} else {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td stle="color:red">提现失败</td></tr>';

											}
										}
										$('#table2').append(_html2)

										form.render();
									} else {
										layer.msg(data.message);
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
              // 黑名单加入与取消
							$('#blacklist').click(function() {
									//执行 Ajax 后重载
									layer.open({
							        type: 1
							        ,title: titles
							        ,area: '300px;'
							        ,shade: 0.8
							        ,id: 'LAY_layuipro'
							        ,btn: ['确认标记','取消',]
							        ,btnAlign: 'c'
							        ,moveType: 1 //拖拽模式，0或者1
							        ,content: '<div style="padding: 50px; line-height: 22px; background-color: #fff; color: #000; font-weight: 300;"><p>'+contents+'</p></div>'
							        ,success: function(layero){
							          var btn = layero.find('.layui-layer-btn');
							          btn.find('.layui-layer-btn0').click(function(){
													$.ajax({
															type: "POST",
															dataType: "json",
															url: "https://bookshop.dingdangtoy.com/api/admin/user/black",
															data: {
																'user_id':data.id,
																'is_black':is_black,
															},
															headers: {
																		'access-token': layui.data('layuiAdmin').access_token
																	},
														success: function(data){
															if(data.code == 0){
																layer.msg('操作成功');
																layui.table.reload('LAY-good-list-status1');
														    layui.table.reload('LAY-good-list-status2');
														    layui.table.reload('LAY-good-list-status3');
														    layui.table.reload('LAY-good-list-status4');
																setTimeout(function(){
																		window.parent.layer.closeAll();
																},1000)
															} else {
																layer.msg(data.message);
															}

														},
														error: function(msg){
															console.log(msg)
														}
													});
							          })
							        }
							      });
								return false;


							})
						});
					}
				});
			}
    });
    table.on('tool(LAY-good-list-status4)', function(obj){
      var data = obj.data;
      if(obj.event === 'edit'){
        admin.popup({
        title: '编辑书评'
        ,area: ['80%', '80%']
        ,id: 'LAY-popup-content-tags'
        ,success: function(layero, index){
          view(this.id).render('book-review/all/add', data).done(function(){
            form.render(null, 'layuiadmin-form-tags');
		   	     $.ajax({
					    type: "GET",
					    dataType: "json",
					    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/show",
					    data: {
					    	id:data.id
					    },
					    headers: { //通过 request 头传递
			              'access-token': layui.data('layuiAdmin').access_token
			            },
								success: function(data){
								    $('#content1').text(data.data.content)
								},
								error: function(msg){
								  console.log(msg)
								}
						});
            if (parseInt(data.state) == 0) {
            	$('#btn-pass').show();
            }
            if (parseInt(data.state) == 1) {
            	$('#pass').show();
            	$('#status-1').show();
            }
            if (parseInt(data.state) == 2) {
            	$('#nopass').show();
            	$('#status-1').show();
            }
            //监听通过提交
            form.on('submit(layuiadmin-app-tags-submit)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':1
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
            //监听不通过提交
            form.on('submit(layuiadmin-app-tags-submit1)', function(data){
              var title = data.field.title; //获取提交的字段
              var sort = data.field.sort;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
	   	        $.ajax({
				    type: "PUT",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/update_state",
				    data: {
				    	id:data.field.id,
				    	'state':2
				    },
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
							success: function(data){
							    if (parseInt(data.code) == 0) {
							    	layer.msg('操作成功');
								    layui.table.reload('LAY-good-list-status1');
								    layui.table.reload('LAY-good-list-status2');
								    layui.table.reload('LAY-good-list-status3');
								    layui.table.reload('LAY-good-list-status4');
							    } else {
							    	layer.msg(data.message);
							    }
							},
							error: function(msg){
							  console.log(msg)
							}
					});
				layer.close(index); //执行关闭
            });
          });
        }
      });
      } else if (obj.event === 'detail') {
				admin.popup({
					title: '查看用户',
					area: ['80%', '96%'],
					id: 'LAY-popup-content-tags',
					success: function(layero, index) {
						view(this.id).render('user-manage/all/add', data).done(function() {
							var is_black = '';
							var titles = '';
							var contents = '';
							// 跳转收书列表
							$('#order_books1').click(function() {
								location.hash = '/buy-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转卖书列表
							$('#order_books').click(function() {
								location.hash = '/sale-orders/all/index/user_id=' + data.user_id
								return false;
							})
							// 跳转订单退回列表
							$('#order_books2').click(function() {
								location.hash = '/return-order/order/index/user_id=' + data.user_id
								return false;
							})
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/user/show?id=" + data.user_id,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(parseInt(data.code) == 0) {
										$('#wechat_avatar1').attr('src', data.data.wechat_avatar)
										$('#wechat_nickname').text(data.data.wechat_nickname)
										$('#account').text(data.data.account)
										$('#created_at').text(data.data.created_at)
										$('#recommend_users_success').text(data.data.recommend_users_success)
										$('#buy_orders_num').text(data.data.buy_orders_num)
										$('#buy_books_num').text(data.data.buy_books_num)
										$('#sell_orders_num').text(data.data.sell_orders_num)
										$('#sell_books_num1').text(data.data.sell_books_num1)
										$('#sell_books_num2').text(data.data.sell_books_num2)
										$('#back_orders_num').text(data.data.back_orders_num)
										$('#back_books_num').text(data.data.back_books_num)
										$('#get_money').text(data.data.get_money)

										if(parseInt(data.data.is_official_account) == 1) {
											$('#wechat_nickname1').text('已关注公众号')
										} else {
											$('#wechat_nickname1').text('未关注公众号')
										}
										if(parseInt(data.data.is_black) == 1) {
											is_black = 0;
											$('#blacklist').text('取消标记黑名单');
											$('#blacklistUser').show();
											titles = '确认将用户取消标记';
											contents = '确认后，该用户的卖书权限将恢复，是否确认操作';
										} else {
											is_black = 1;
											$('#blacklist').text('标记为黑名单用户');
											titles = '确认将用户标记为黑名单';
											contents = '提交后，该用户卖书下单时将会被系统自动拒绝是否确认操作？';
										}
										$('#recommend_users_total').text(data.data.recommend_users_total)
										if(data.data.addresses.length > 0) {
											$('#base-address').show();
										}
										var _html = '';
										var _html1 = '';
										var _html2 = '';
										var num = 0;
										for(var i = 0; i < data.data.addresses.length; i++) {
											num += 1
											_html += '<li><p>地址信息' + num + '</p><p><span style="margin-right:20px">' + data.data.addresses[i].receiver + '</span>' + data.data.addresses[i].mobile + '</p><p>' + data.data.addresses[i].province_name + '' + data.data.addresses[i].city_name + '' + data.data.addresses[i].area_name + '' + data.data.addresses[i].address + '</p></li>';
										}
										$('#address-list').append(_html)
										for(var i = 0; i < data.data.account_records1.length; i++) {
											_html1 += '<tr><td>卖书（' + data.data.account_records1[i].books_num + '本）</td><td>' + data.data.account_records1[i].created_at + '</td><td>' + data.data.account_records1[i].platform_success_time + '</td><td>' + data.data.account_records1[i].actual_price + '</td></tr>';
										}
										$('#table1').append(_html1)
										for(var i = 0; i < data.data.account_records2.length; i++) {
											if(parseInt(data.data.account_records2[i].state) == 1) {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td>提现成功</td></tr>';
											} else {
												_html2 += '<tr><td>' + data.data.account_records2[i].remark + '</td><td>' + data.data.account_records2[i].created_at + '</td><td>' + data.data.account_records2[i].account + '</td><td stle="color:red">提现失败</td></tr>';

											}
										}
										$('#table2').append(_html2)

										form.render();
									} else {
										layer.msg(data.message);
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
              // 黑名单加入与取消
							$('#blacklist').click(function() {
									//执行 Ajax 后重载
									layer.open({
							        type: 1
							        ,title: titles
							        ,area: '300px;'
							        ,shade: 0.8
							        ,id: 'LAY_layuipro'
							        ,btn: ['确认标记','取消',]
							        ,btnAlign: 'c'
							        ,moveType: 1 //拖拽模式，0或者1
							        ,content: '<div style="padding: 50px; line-height: 22px; background-color: #fff; color: #000; font-weight: 300;"><p>'+contents+'</p></div>'
							        ,success: function(layero){
							          var btn = layero.find('.layui-layer-btn');
							          btn.find('.layui-layer-btn0').click(function(){
													$.ajax({
															type: "POST",
															dataType: "json",
															url: "https://bookshop.dingdangtoy.com/api/admin/user/black",
															data: {
																'user_id':data.id,
																'is_black':is_black,
															},
															headers: {
																		'access-token': layui.data('layuiAdmin').access_token
																	},
														success: function(data){
															if(data.code == 0){
																layer.msg('操作成功');
																layui.table.reload('LAY-good-list-status1');
														    layui.table.reload('LAY-good-list-status2');
														    layui.table.reload('LAY-good-list-status3');
														    layui.table.reload('LAY-good-list-status4');
																setTimeout(function(){
																		window.parent.layer.closeAll();
																},1000)
															} else {
																layer.msg(data.message);
															}

														},
														error: function(msg){
															console.log(msg)
														}
													});
							          })
							        }
							      });
								return false;


							})
						});
					}
				});
			}
    });


  });
</script>
  <style type="text/css">
  	.layui-table-cell, .layui-table-tool-panel li{white-space: inherit !important;}
  	.sp1{float: left;}
  	.sp2{float: left;width: 16px;margin-top: 5px;height: 16px;text-align: center;line-height: 16px;font-size: 14px;color: #ccc;border: 1px solid #ccc;border-radius: 50%;margin-left: 15px;cursor: pointer;}
  </style>
